// miniprogram/group_admin/pages/myOder/myOder.js
// 获取api
const api = require("../../../utils/api.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
     //默认为‘待付款 0 已付款 1’
     isTrue:0,
     orderContentModule:""
  },
    // 显示未付款
 noMoney:function(){
  var that = this;
  // var studyMOdelList=this.data.studyList;
  that.setData({
    isTrue: 0,
    // studyNewList:studyMOdelList.weakList
  })
  },
   // 显示已付款
 yesMoney:function(){
  var that = this;
  // var studyMOdelList=this.data.studyList;
  that.setData({
    isTrue: 1,
    // studyNewList:studyMOdelList.masterList
  })
 },
 //去付款
 goMoney:function(e){
  var index=e.currentTarget.dataset.index;
  var loadMemberSystemId=this.data.orderList[index].memberSystemId;
    wx.navigateTo({
      url: '/group_admin/pages/sureOrder/sureOrder?loadMemberSystemId='+loadMemberSystemId,
    })
 },

 goToMoney:function(e){
  // 得到订单guid
   var orderguid=e.currentTarget.dataset.orderguid;
   var coursename=e.currentTarget.dataset.coursename;
   var finishtime=e.currentTarget.dataset.finishtime;
   var expirationtime=e.currentTarget.dataset.expirationtime;
   var index=e.currentTarget.dataset.index;
   var orderModule=this.data.orderList[index].module;

   console.log("index----------"+index);
   
   console.log("orderModule----------"+orderModule);
  this.setData({
    "orderIndex":index
  })
   console.log("e.currentTarget.dataset.expirationtime"+expirationtime);
  //  跳转到订单详情页面
    wx.navigateTo({
      url: '/group_admin/pages/orderContent/orderContent?orderguid='+orderguid+'&finishtime='+finishtime+'&coursename='+coursename+'&expirationtime='+expirationtime+'&orderModule='+orderModule
    })

 },
  // 显示 隐藏Toast
  showHideToast:function(){
    wx.showLoading({
      title: '加载中',
    })
    setTimeout(function () {
      wx.hideLoading()
    }, 2000)
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    this.showHideToast();

    // 获取用户的sessionid uid
    var resYtkUserInfo= wx.getStorageSync("USERDATA");

    var params = {
      "sessionid": resYtkUserInfo.sessionid,
      "uid": resYtkUserInfo.uid,
      //  "sessionid": "ba82cc3a323e4f5da6e422c39b171d4c",
      //  "uid": "462D049EB2338AFA",
      "pagesize":20,
      "pagecurrent":1,
      // 全部：-1 未完成：0 已完成：1
      "state":-1,
    };
    var url = "/order/myOrderList";
    var that = this;
    api.sendPosts( url,params, function(res) {
      var noMoneyLength=0;
      var yesMoneyLength=0;
      for(var i=0;i<res.data.length;i++){
        //未付款
        if(res.data[i].state==1){
          yesMoneyLength++;
        }else {
          noMoneyLength++;
        }
      }
      that.setData({
        "orderList": res.data,
        "noMoneyLength":noMoneyLength,
        "yesMoneyLength":yesMoneyLength,
        });
    });

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})